Universal Access To All Knowledge
Home Donate | Store | Blog | FAQ | Jobs | Volunteer Positions | Contact | Bios | Forums | Projects | Terms, Privacy, & Copyright
Search: Advanced Search
Anonymous User (login or join us)

Reply to this post | See parent post | Go Back
View Post [edit]

Poster: Moongleam Date: Sep 11, 2009 7:44am
Forum: feature_films Subject: Re: Want to remove logos (watermarks)?

We'll be removing logos from an mpeg2 file that was extracted from
a DVD.

Install AviSynth, VirtualDub, and XnView.

Download this:
You'll need two files from it.
Put DGIndex.exe in your path or in the directory where you will put
the .avs text files and the movie files.
Put DGDecode.dll in your AviSynth plugins directory
(this gives AviSynth the "MPEG2Source" command).

Using Notepad or your favorite text-editor (don't use a
word-processor), create a file named "hide.avsi" that contains
this (copy and paste):

## --- Beginning of program. ---

function big_blur( clip victim )
b1 = 1.0
b2 = 1.58
return victim.blur(b1).blur(b1).blur(b1).blur(b2).blur(b2).blur(b2)

function hide_hor_rectangle( clip clip_in, \
int "x", int "y", int "width", int "height", \
int "favor_top_or_bottom" )
favor_top_or_bottom = default( favor_top_or_bottom, 0 )
clip_in = clip_in.convertToRGB32()
line_top = clip_in.Crop( x, y - 1, width, 1)
line_bot = clip_in.Crop( x, y + height, width, 1)
line_left = clip_in.Crop( x-1, y, 1, height )
line_right = clip_in.Crop( x+width, y, 1, height )

replacement = stackVertical( \
line_top, \
line_top.Layer( line_bot, "add", 48, 0, 0 ), \
line_top.Layer( line_bot, "add", 128, 0, 0 ), \
line_bot.Layer( line_top, "add", 48, 0, 0 ), \
line_bot )
replacement = ( favor_top_or_bottom == 0 ) ? \
stackVertical( line_top, replacement, line_bot ) : \
( favor_top_or_bottom > 0 ) ? \
stackVertical( line_top, line_top, line_top, replacement ) : \
stackVertical( replacement, line_bot, line_bot, line_bot )

replacement = replacement.BilinearResize( width, height )

line_left = stackHorizontal(line_left,line_left)
line_right = stackHorizontal(line_right,line_right)
replacement = replacement.Layer(line_left,"add",256, 0,0)
replacement = replacement.Layer(line_right,"add",256, width-2,0)

line_left = stackHorizontal(line_left,line_left)
line_right = stackHorizontal(line_right,line_right)
replacement = replacement.Layer(line_left,"add",128, 2,0)
replacement = replacement.Layer(line_right,"add",128, width-6,0)

replacement = replacement.big_blur

return clip_in.Layer( replacement, "add", 256, x, y )

function apply_to_frames( clip source, string func, \
int first_frame, int last_frame )
source = source.convertToRGB32()
skipped = trim( source, 0, (first_frame - 1) )
processed = apply( func, trim( source, first_frame, last_frame ) )
remaining = trim( source, last_frame + 1, 0 )
return skipped + processed + remaining

## --- End of program. ---

Let's assume that you have an mpeg2 file named "Badly_Marked.mpeg"
that has the oval millcreek logos in the lower, right corner of the
picture. Put the mpeg2 file in the same directory where the
"hide.avsi" file is.

To enable AviSynth to handle the mpeg2 file, an index file
has to be created. Start up DGIndex and load the mpeg2 file.
Then execute "File / Save Project". (This also creates a
separate audio file that will be needed when the movie is
transcoded.) Exit the program.

Using Notepad or your favorite text-editor (don't use a
word-processor), in the directory where you put "hide.avsi" create a
file named "millcreek.avs" that contains this (copy and paste):

import( "hide.avsi" )

MPEG2Source( "Badly_Marked.d2v" )

Note the filename extension: ".d2v", not ".mpeg".

Now run VirtualDub and load the file "millcreek.avs". Hit the button
in the upper, right corner to make the window fill the screen. We'll
be using the left video pane; ignore the right one. You can drag the
slider at the bottom of the window to navigate through the movie.
Another way is to use ALT-RIGHT-ARROW or ALT-LEFT-ARROW to jump 50
frames forward or backward; use the arrows without ALT to move a frame
at a time. Find a frame that has the logo that you want to remove.
Select menu item "Video / Copy source frame to clipboard".

Start up XnView. Under menu "File", select "Import Clipboard". To
make the picture larger, select "View / Zoom / 200%". Drag with
the mouse to create a box that just contains the logo; release the
mouse button and drag the sides of the box until the fit is
perfect. Now grab the upper, left corner of the box without
moving it. At the bottom of the window you will see four important
numbers: the location of the upper-left corner of the box and its
width and height. Write down those four numbers. Exit the program.

Now that we know the location and size of the rectangle that must be
hidden, we can add the needed functions to the text file
"millcreek.avs" that we already created, making it look like this:

import( "hide.avsi" )

function hide_millcreek_oval( clip source, int "favored" )
favored = default( favored, 0 )
return hide_hor_rectangle(source, 520, 400, 168, 60, favored )

function hide_millcreek_oval_top( clip source )
return hide_millcreek_oval(source, 1 )

function hide_millcreek_oval_bottom( clip source )
return hide_millcreek_oval(source, -1 )

MPEG2Source( "Badly_Marked.d2v" )

(A word of advice. When editing this file, don't insert tab characters.
Just use the space-bar.)

Let me explain the two extra functions "hide_millcreek_oval_top()"
and "hide_millcreek_oval_bottom()". By default, the function
"hide_hor_rectangle()" works like this: it takes a horizontal line
from just above the rectangle and smears it down half the height of
the rectangle, and it takes a line from below the rectagnle and smears
it halfway up. Sometimes, however, it would look better to smear the
top line more than halfway down; that's what hide_millcreek_oval_top()

Now we're ready to locate precisely each logo in the movie.
Switch back to VirtualDub and find the first watermark in the movie.
Move to the first frame in which the logo appears. At the bottom of
the window, the number of the frame is shown. Use the mouse to drag
and copy that number. Switch back to the text-editor and paste that
number at the bottom of the file; type a comma just after the number.
Back in VirtualDub, find the last frame in which the logo appears (the
logos usually last about 20 seconds). Copy the number, and, in the
text-editor, past it just after the comma.

Repeat this for each appearance of a watermark.

Now that we have the numbers, we can wrap them in the necessary code,
giving us something like this:

apply_to_frames( "hide_millcreek_oval", 637,1238 )

apply_to_frames( "hide_millcreek_oval", 34126,34730 )

apply_to_frames( "hide_millcreek_oval", 72055,72659 )

apply_to_frames( "hide_millcreek_oval", 108926,109514 )

Your numbers, of course, will be different. You could copy the
code above and paste it into the text-editor at the bottom of the
file and then edit the numbers. Don't forget to save these
changes to the file before proceding to the next step, but don't
close the text-editor. We'll need the logo locations for the next

Switch back to VirtualDub, and tell it to reload the file (File /
Reopen video file). Since we have already noted the frame-location of
each watermark, it is fairly easy to find each one and see if it is
being properly removed. And now is a good time to determine which
function would be best for each watermark. Remember to reload the
file into VirtualDub if you make any changes to it with the

Close VirtualDub. Now we're ready to transcode the movie. Your
transcoding program must be told to take the audio from the separate
audio file that was created by DGIndex. For the name of the source
video file, use "millcreek.avs". If, for example, you are using
mencoder, something like this would have to be in your command line:

millcreek.avs -audiofile "Badly_Marked T01 2_0ch 256Kbps DELAY 141ms.ac3"

When it comes time to process your next millcreek movie, edit the file
"millcreek.avs" in this way. Copy the lines that are specific to the
last movie you processed, and paste them at the end of the file; then
change only the parts that need to be changed. Don't remove the lines
that pertain to the previous movie; those lines will serve as an
example in the future, and you may even want to transcode that movie
again someday. Instead, turn the lines into comments, like this:

# MPEG2Source( "Badly_Marked.d2v" )

# apply_to_frames( "hide_millcreek_oval", 637,1238 )

# apply_to_frames( "hide_millcreek_oval", 34126,34730 )

# apply_to_frames( "hide_millcreek_oval", 72055,72659 )

# apply_to_frames( "hide_millcreek_oval", 108926,109514 )

If you decide that you want to clean up the watermarks in tcm movies,
then make a copy of the file "millcreek.avs" with the name "tcm.avs".
In your text-editor, do a search-and-replace to change all instances
of "millcreek_oval" to "tcm". Then use the process described above
to find the numbers for the rectangle that must be hidden.

I recently examined a movie that had 9 occurrences of the A&E logo.
That inspired the following function.

function delogo_AE( clip source, int "favored" )
favored = default( favored, 0 )
## Assuming picture is 720x480.
return hide_hor_rectangle(source, 532,354, 124,86, favored )

This post was modified by Moongleam on 2009-09-11 14:44:29

Reply to this post
Reply [edit]

Poster: guyzilla Date: Sep 11, 2009 11:18pm
Forum: feature_films Subject: Re: Want to remove logos (watermarks)?

Would it matter if the ORIGINAL source material was a VHS tape? That's where 99% of the stuff that I upload comes from. It's transferred to dvd-r or rw then converted to divx. I don't know if that's important or not. Some of my prospective sources have a watermark on the videotape image. Would it work on those? And would it work with DivX Author?

This post was modified by guyzilla on 2009-09-12 06:18:46